package com.example.controller.sys;

import com.example.pojo.Process;
import com.example.pojo.ProcessClassify;
import com.example.service.IProcessClassifyService;
import com.example.service.IProcessService;
import com.example.vo.ResultVo;
import io.swagger.annotations.ApiOperation;
import org.omg.CosNaming.NamingContextExtPackage.StringNameHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import java.util.Arrays;

/**
 * <p>
 * 流程分类表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2022-04-10
 */
@RestController
@RequestMapping("/sys/process-classify")
@Api(tags = "流程分类管理",value = "")
public class ProcessClassifyController {

    @Autowired
    private IProcessClassifyService processClassifyService;

    @ApiOperation("流程类别查询")
    @GetMapping("/query")
    public ResultVo getProClassify(){
        return processClassifyService.getProClassify();
    }

    @ApiOperation(value = "新增流程类别")
    @PostMapping("/add")
    public ResultVo addProcessClassify(@RequestBody ProcessClassify processClassify){
        if(processClassifyService.save(processClassify)){
            return ResultVo.ok("新增成功");
        }
        return ResultVo.error("新增失败!");
    }

    @ApiOperation(value = "修改流程类别")
    @PutMapping("/update")
    public ResultVo updateProcessClassify(@RequestBody ProcessClassify processClassify){
        if(processClassifyService.updateById(processClassify)){
            return ResultVo.ok("修改成功");
        }
        return ResultVo.error("修改失败!");
    }

    @ApiOperation(value = "删除流程类别")
    @DeleteMapping("/delete")
    public ResultVo deleteProcessClassify(Integer[] ids){
        if(processClassifyService.removeByIds(Arrays.asList(ids))){
            return ResultVo.ok("删除成功");
        }
        return ResultVo.error("删除失败!");
    }

    @ApiOperation(value = "流程类别选项")
    @GetMapping("/options")
    public ResultVo getProcessClassifyOptions(){
        return processClassifyService.getProClassifyOptions();
    }

    @ApiOperation(value = "判断是否存在其它同名流程类别")
    @GetMapping("/has-some-name")
    public Boolean hasSomeNameProClassify(Integer id,@RequestParam(name = "name")String name){
        return processClassifyService.hasSomeNameProClassify(id,name);
    }
}
